This returns a GFile which can represent both the above.
GtkIconTheme *icon_theme;
const char *name;
GtkIconPaintable *info;
- GFile *file;
name = gtk_image_get_icon_name (GTK_IMAGE (data));
icon_theme = gtk_icon_theme_get_for_display (gtk_widget_get_display (GTK_WIDGET (data)));
32, 1,
gtk_widget_get_direction (GTK_WIDGET (data)),
0);
- file = g_file_new_for_path (gtk_icon_paintable_get_filename (info));
- g_value_set_object (value, file);
- g_object_unref (file);
+ g_value_take_object (value, gtk_icon_paintable_get_file (info));
g_object_unref (info);
}
gtk_icon_theme_lookup_by_gicon
gtk_icon_theme_list_icons
gtk_icon_theme_get_icon_sizes
-gtk_icon_paintable_get_filename
-gtk_icon_paintable_get_resource_path
+gtk_icon_paintable_get_file
gtk_icon_paintable_get_icon_name
gtk_icon_paintable_is_symbolic
<SUBSECTION Standard>
gobject_class->finalize = gtk_icon_paintable_finalize;
}
-/**
- * gtk_icon_paintable_get_filename:
- * @self: a #GtkIcon
- *
- * Gets the filename for the icon.
- *
- * Returns: (nullable) (type filename): the filename for the icon, or %NULL
- * if the icon is not represented by a filename.
- */
-const gchar *
-gtk_icon_paintable_get_filename (GtkIconPaintable *icon)
+static GFile *
+new_resource_file (const char *filename)
{
- g_return_val_if_fail (icon != NULL, NULL);
+ char *escaped = g_uri_escape_string (filename,
+ G_URI_RESERVED_CHARS_ALLOWED_IN_PATH, FALSE);
+ char *uri = g_strconcat ("resource://", escaped, NULL);
+ GFile *file = g_file_new_for_uri (uri);
- if (!icon->is_resource)
- return icon->filename;
- return NULL;
+ g_free (escaped);
+ g_free (uri);
+
+ return file;
}
/**
- * gtk_icon_paintable_get_resource_path:
+ * gtk_icon_paintable_get_file:
* @self: a #GtkIcon
*
- * Gets the resource path for the icon.
+ * Gets the #GFile that was used to load the icon, or %NULL if the icon was
+ * not loaded from a file.
*
- * Returns: (nullable) (type filename): the resource for the icon, or %NULL
- * if the icon is not represented by a resource.
+ * Returns: (nullable) (transfer full): the #GFile for the icon, or %NULL.
+ * Free with g_object_unref().
*/
-const gchar *
-gtk_icon_paintable_get_resource_path (GtkIconPaintable *icon)
+GFile *
+gtk_icon_paintable_get_file (GtkIconPaintable *icon)
{
- g_return_val_if_fail (icon != NULL, NULL);
+ if (icon->filename)
+ {
+ if (icon->is_resource)
+ return new_resource_file (icon->filename);
+ else
+ return g_file_new_for_path (icon->filename);
+ }
- if (icon->is_resource)
- return icon->filename;
return NULL;
}
GType gtk_icon_paintable_get_type (void) G_GNUC_CONST;
GDK_AVAILABLE_IN_ALL
-const gchar * gtk_icon_paintable_get_filename (GtkIconPaintable *self);
-GDK_AVAILABLE_IN_ALL
-const gchar * gtk_icon_paintable_get_resource_path (GtkIconPaintable *self);
+GFile * gtk_icon_paintable_get_file (GtkIconPaintable *self);
GDK_AVAILABLE_IN_ALL
const gchar * gtk_icon_paintable_get_icon_name (GtkIconPaintable *self);
GDK_AVAILABLE_IN_ALL
}
else if (strcmp (argv[1], "lookup") == 0)
{
+ GFile *file;
+
if (argc < 4)
{
g_object_unref (icon_theme);
scale = atoi (argv[5]);
icon = gtk_icon_theme_lookup_icon (icon_theme, argv[3], NULL, size, scale, direction, flags);
+ file = gtk_icon_paintable_get_file (icon);
g_print ("icon for %s at %dx%d@%dx is %s\n", argv[3], size, size, scale,
- icon ? gtk_icon_paintable_get_filename (icon) : "<none>");
-
- if (icon)
- {
- GdkPaintable *paintable = GDK_PAINTABLE (icon);
+ file ? g_file_get_uri (file) : "<none>");
- g_print ("texture size: %dx%d\n", gdk_paintable_get_intrinsic_width (paintable), gdk_paintable_get_intrinsic_height (paintable));
-
- g_object_unref (icon);
- }
+ g_print ("texture size: %dx%d\n", gdk_paintable_get_intrinsic_width (GDK_PAINTABLE (icon)), gdk_paintable_get_intrinsic_height (GDK_PAINTABLE (icon)));
+ g_object_unref (icon);
}
else
{
gint pixbuf_size)
{
GtkIconPaintable *info;
+ GFile *file;
+ char *path = NULL;
if (fallbacks)
{
return;
}
+ file = gtk_icon_paintable_get_file (info);
+ if (file)
+ {
+ path = g_file_get_path (file);
+ g_object_unref (file);
+ }
+
if (filename)
{
- if (!g_str_has_suffix (gtk_icon_paintable_get_filename (info), filename))
+ if (path == NULL || !g_str_has_suffix (path, filename))
{
g_error ("Icon for \"%s\" with flags %s at size %d should be \"...%s\" but is \"...%s\"",
icon_name, lookup_flags_to_string (flags), size,
- filename, gtk_icon_paintable_get_filename (info) + strlen (g_get_current_dir ()));
+ filename, path);
return;
}
}
else
{
- g_assert (gtk_icon_paintable_get_filename (info) == NULL);
+ g_assert (path == NULL);
}
+ g_free (path);
+
g_assert_cmpint (gdk_paintable_get_intrinsic_width (GDK_PAINTABLE (info)), ==, size);
g_object_unref (info);